package util

import (
	"github.com/golang/protobuf/proto"
	"go_server/game_server/protocol/pb"
	"go_server/zinx/ziface"
	"go_server/zinx/zlog"
)

func PBParseRet(request ziface.IRequest, msg proto.Message) bool {
	err := proto.Unmarshal(request.GetData(), msg)
	if err != nil {
		zlog.Errorf("解析客户端消息失败, msgId: %d, err:%v", request.GetMsgID(), err)
		conn := request.GetConnection()
		errMsg := &pb.ErrorCodeS2C{
			Cmd: int32(request.GetMsgID()),
			Code: pb.ErrorCodeManager_PB_DESERIAL_FAIL,
		}
		conn.SendBuffPBMsg(uint32(pb.ProtocolManager_ErrorCode), errMsg)
		return false
	}
	return true
}
